# 1 CircuitPython基础
# https://learn.adafruit.com/welcome-to-circuitpython
# https://learn.adafruit.com/keep-your-circuitpython-libraries-on-devices-up-to-date-with-circup

# 基础模块
import board
dir(board)
print("开发板名称:", board.board_id)

# 引脚定义
import re

attrs = [i for i in dir(board) if not re.match(r'^[A-Z]', i)]
GPIOS = [i for i in dir(board) if re.match(r'^[A-Z]', i)]
gpio_used = []

print("数字引脚：", end="")
for i in GPIOS:
    if re.match(r'^D\d+', i):
        print(i, end=" ")
        gpio_used.append(i)
print("")

print("模拟引脚：", end="")
for i in GPIOS:
    if re.match(r'^A\d+', i):
        print(i, end=" ")
        gpio_used.append(i)
print("")

print("TFT：", end="")
for i in GPIOS:
    if re.match(r'^TFT|DISPLAY', i):
        print(i, end=" ")
        gpio_used.append(i)
print("")

print("串口：", end="")
for i in GPIOS:
    if re.match(r'^(TX|RX|UART)$', i):
        print(i, end=" ")
        gpio_used.append(i)
print("")

print("炫彩灯珠：", end="")
for i in GPIOS:
    if re.match(r'^NEOPIXEL', i):
        print(i, end=" ")
        gpio_used.append(i)
print("")

print("SPI：", end="")
for i in GPIOS:
    if re.match(r'^(MOSI|MISO|SCK|SPI)', i):
        print(i, end=" ")
        gpio_used.append(i)
print("")

print("I2C：", end="")
for i in GPIOS:
    if re.match(r'.*(SCL|SDA|I2C)', i):
        print(i, end=" ")
        gpio_used.append(i)
print("")

print("按键：", end="")
for i in GPIOS:
    if re.match(r'^(BUTTON|BOOT0)', i):
        print(i, end=" ")
        gpio_used.append(i)
print("")

print("LED：", end="")
for i in GPIOS:
    if re.match(r'(LED|L)', i):
        print(i, end=" ")
        gpio_used.append(i)
print("")

gpio_unused = [i for i in GPIOS if i not in gpio_used]
if len(gpio_unused):
    print("未分类属性：", gpio_unused)
if len(attrs):
    print("其他属性", attrs)


# 查看加载的模块
#help("modules")
